Optimal Path Planning In Dynamic Environments